package com.jie.thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.net.URL;

public class    ThreadTest implements Runnable{
    private String url;
    private String name;

    public static void main(String[] args) {
        ThreadTest threadTest = new ThreadTest("http://img.jj20.com/up/allimg/1114/0G520141919/200G5141919-3-1200.jpg","古风.jpg");
        ThreadTest threadTest2 = new ThreadTest("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.desktx.cc%2Fd%2Ffile%2Fwallpaper%2Fgame%2F20170321%2F016b57969e6c5d6f7ef1fc496647da17.jpg&refer=http%3A%2F%2Fwww.desktx.cc&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1637656029&t=709664761a86dc297cf83b17e5a3fac5","花木兰.jpg");

        ThreadTest threadTest3 = new ThreadTest("http://n.sinaimg.cn/front/148/w640h308/20190206/UCv7-hsqyiwt7186339.jpg","不知火舞.jpg");
        new Thread(threadTest).start();
        new Thread(threadTest2).start();
        new Thread(threadTest3).start();

    }

    public ThreadTest(String url, String name) {
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {
        WebDownloader webDownloader = new WebDownloader();
        try {
            webDownloader.webDownloda(url,name);
            System.out.println("图片"+name+"下载完成...");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
class  WebDownloader {
    public void webDownloda(String url,String name) throws Exception{
        FileUtils.copyURLToFile(new URL(url),new File(name));
    }
    
}
